#include "dkglViewVolume.h"

namespace DKGL
{

OrthoViewVolume::OrthoViewVolume(){}

OrthoViewVolume::OrthoViewVolume(const dbRect2D& np, double nearDist, double farDist) :
	ViewVolume(np, nearDist, farDist)
{
	_updateProjMatrix();
}

OrthoViewVolume::OrthoViewVolume(const OrthoViewVolume& ovv)
{
	for(int i=0;i<16;i++)
	{
		mProjMatrix[i] = ovv.mProjMatrix[i];
	}

	mNearClipPlane = ovv.mNearClipPlane;
	mNear = ovv.mNear;
	mFar = ovv.mFar;

	_updateProjMatrix();
}

OrthoViewVolume::OrthoViewVolume(const PersViewVolume& pvv)
{}

void OrthoViewVolume::setProjection()
{
	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(mProjMatrix);
}

void OrthoViewVolume::_updateProjMatrix()
{
	float tmp[16];

	glMatrixMode(GL_PROJECTION);
	
	// save current projection matrix
	glGetFloatv(GL_PROJECTION_MATRIX, tmp);

	glLoadIdentity();
	glOrtho(-mNearClipPlane.width/2, mNearClipPlane.width/2, 
		-mNearClipPlane.height/2, mNearClipPlane.height/2,
		mNear, mFar);

	glGetFloatv(GL_PROJECTION_MATRIX, mProjMatrix);
	
	// restore the previous projection matrix
	glLoadMatrixf(tmp);
}

}